package com.ruoyi.business.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.HsUnits;
import com.ruoyi.business.service.IHsUnitsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单元Controller
 * 
 * @author asher
 * @date 2021-11-08
 */
@RestController
@RequestMapping("/business/unit")
public class HsUnitsController extends BaseController
{
    @Autowired
    private IHsUnitsService hsUnitsService;

    /**
     * 查询单元列表
     */
    @PreAuthorize("@ss.hasPermi('business:units:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsUnits hsUnits)
    {
        startPage();
        List<HsUnits> list = hsUnitsService.selectHsUnitsList(hsUnits);
        return getDataTable(list);
    }

    /**
     * 导出单元列表
     */
    @PreAuthorize("@ss.hasPermi('business:units:export')")
    @Log(title = "单元", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsUnits hsUnits)
    {
        List<HsUnits> list = hsUnitsService.selectHsUnitsList(hsUnits);
        ExcelUtil<HsUnits> util = new ExcelUtil<HsUnits>(HsUnits.class);
        return util.exportExcel(list, "单元数据");
    }

    /**
     * 获取单元详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:units:query')")
    @GetMapping(value = "/{unitId}")
    public AjaxResult getInfo(@PathVariable("unitId") Long unitId)
    {
        return AjaxResult.success(hsUnitsService.selectHsUnitsByUnitId(unitId));
    }

    /**
     * 新增单元
     */
    @PreAuthorize("@ss.hasPermi('business:units:add')")
    @Log(title = "单元", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsUnits hsUnits)
    {
        return toAjax(hsUnitsService.insertHsUnits(hsUnits));
    }

    /**
     * 修改单元
     */
    @PreAuthorize("@ss.hasPermi('business:units:edit')")
    @Log(title = "单元", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsUnits hsUnits)
    {
        return toAjax(hsUnitsService.updateHsUnits(hsUnits));
    }

    /**
     * 删除单元
     */
    @PreAuthorize("@ss.hasPermi('business:units:remove')")
    @Log(title = "单元", businessType = BusinessType.DELETE)
	@DeleteMapping("/{unitIds}")
    public AjaxResult remove(@PathVariable Long[] unitIds)
    {
        return toAjax(hsUnitsService.deleteHsUnitsByUnitIds(unitIds));
    }
}
